﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DmgEnemy : MonoBehaviour {

    Animator am;
    EnemyController enemy;

    public Transform player;
    void Start()
    {
        am = transform.parent.GetComponent<Animator>();
        enemy = transform.parent.GetComponent<EnemyController>();
    }

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag.Equals("PlayerArm"))
        {
            am.SetTrigger("Dmg");
            transform.parent.GetComponent<EnemyController>().hp -= player.GetComponent<PlayerController>().atk;
            enemy.isDmg = true;
        }

        if (other.gameObject.tag.Equals("PlayerWeapon"))
        {
            Destroy(other.gameObject);
            am.SetTrigger("Dmg");
            transform.parent.GetComponent<EnemyController>().hp -= player.GetComponent<PlayerController>().atk;
            enemy.isDmg = true;
        }
    }
}
